using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using MyMES.Dto;
using MyMES.IServices.MeadingManage;
using System.Threading.Tasks;
using VOL.Core.Controllers.Basic;
using VOL.Core.Filters;
using VOL.Core.Utilities.Response;
using VOL.Entity.AttributeManager;
using VOL.Entity.MeadingManage;

namespace VOL.WebApi.Controllers.MyMES
{
    /// <summary>
    /// 生产报工管理控制器
    /// </summary>
    [Route("api/MeadingReport")]
    [ApiController]
    [AllowAnonymous] // 允许匿名访问
    [PermissionTable(Name = "MeadingReport")]
    public class MeadingReportController : ApiBaseController<IMeadingReportService>
    {
        private readonly IMeadingReportService _meadingReportService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="meadingReportService">生产报工服务</param>
        public MeadingReportController(IMeadingReportService meadingReportService)
            : base(meadingReportService)
        {
            _meadingReportService = meadingReportService;
        }

        /// <summary>
        /// 获取生产报工列表
        /// </summary>
        /// <param name="dto">查询参数</param>
        /// <returns>生产报工列表</returns>
        [HttpPost("GetMeadingReports")]
        public async Task<ActionResult> GetMeadingReports([FromBody] GetMeadingRepotDto dto)
        {
            return Json(await _meadingReportService.GetMeadingRepot(dto));
        }

        /// <summary>
        /// 添加生产报工
        /// </summary>
        /// <param name="meadingReport">生产报工实体</param>
        /// <returns>操作结果</returns>
        [HttpPost("AddMeadingReport")]
        public async Task<WebResponseContent> AddMeadingReport([FromBody] MeadingReport meadingReport)
        {
            return await _meadingReportService.AddMeadingRepot(meadingReport);
        }

        /// <summary>
        /// 更新生产报工
        /// </summary>
        /// <param name="meadingReport">生产报工实体</param>
        /// <returns>操作结果</returns>
        [HttpPost("UpdMeadingReport")]
        public async Task<WebResponseContent> UpdMeadingReport([FromBody] MeadingReport meadingReport)
        {
            return await _meadingReportService.UpdMeadingRepot(meadingReport);
        }

        /// <summary>
        /// 删除生产报工
        /// </summary>
        /// <param name="ids">生产报工ID列表，以逗号分隔的字符串</param>
        /// <returns>操作结果</returns>
        [HttpPost("DelMeadingReport")]
        public async Task<WebResponseContent> DelMeadingReport([FromQuery] string ids)
        {
            return await _meadingReportService.DelMeadingRepot(ids);
        }

        /// <summary>
        /// 获取工单列表
        /// </summary>
        /// <param name="dto">查询参数</param>
        /// <returns>工单列表</returns>
        [HttpPost("GetWorkOrder")]
        public async Task<ActionResult> GetWorkOrder([FromBody] GetWorkOrderDto dto)
        {
            return Json(await _meadingReportService.GetWorkOrder(dto));
        }

        /// <summary>
        /// 获取工作站列表
        /// </summary>
        /// <returns>工作站列表</returns>
        [HttpGet("GetWorkStation")]
        public async Task<WebResponseContent> GetWorkStation()
        {
            return await _meadingReportService.GetWorkStation();
        }

        /// <summary>
        /// 获取部门列表
        /// </summary>
        /// <returns>部门层级结构列表</returns>
        [HttpGet("GetDepartmentsList")]
        public async Task<WebResponseContent> GetDepartmentsList()
        {
            return await _meadingReportService.GetDepartmentsList();
        }

        /// <summary>
        /// 获取用户列表
        /// </summary>
        /// <param name="useName">用户名或真实姓名(可选)</param>
        /// <param name="phone">电话号码(可选)</param>
        /// <param name="departmentId">部门ID(可选)</param>
        /// <returns>用户列表</returns>
        [HttpGet("GetUserList")]
        public async Task<WebResponseContent> GetUserList(
            [FromQuery] string? useName, 
            [FromQuery] string? phone, 
            [FromQuery] string? departmentId)
        {
            return await _meadingReportService.GetUserList(useName, phone, departmentId);
        }
    }
} 